// ignore_for_file: prefer_typing_uninitialized_variables, must_be_immutable, sort_child_properties_last

import 'package:aitao_flutter/style/radius_style.dart';
import 'package:aitao_flutter/style/text_style.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../style/color_style.dart';

class BackNavigation extends StatelessWidget implements PreferredSizeWidget {
  BackNavigation(
      {Key? key,
      this.title = 'Title',
      this.rightTitle = '',
      this.rightBtnCallBack,
      this.leftBtnCallBack,
      this.rightIcon = '',
      this.backArrowColor = ColorStyle.normalTextColor,
      this.backGroundColor = ColorStyle.whiteColor,
      this.titleColor = ColorStyle.normalTextColor,
      this.rightTitleColor = ColorStyle.normalTextColor,
      this.rightFinishBtn = false})
      : super(key: key);
  String title;
  Color titleColor;
  String rightTitle;
  Color rightTitleColor;
  String rightIcon;
  Color backGroundColor;

  Color backArrowColor;
  final leftBtnCallBack;
  final rightBtnCallBack;
  bool rightFinishBtn;
  @override
  Size get preferredSize => Size(ScreenUtil().setWidth(double.infinity), 44);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: backGroundColor,
      padding: const EdgeInsets.fromLTRB(0, 0, 0, 11),
      alignment: Alignment.bottomCenter,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
              flex: 1,
              child: GestureDetector(
                child: Icon(
                  Icons.arrow_back_ios_new_outlined,
                  color: backArrowColor,
                  size: 20.w,
                ),
                onTap: () {
                  leftBtnCallBack != null ? leftBtnCallBack() : Get.back();
                },
              )),
          // const Spacer(),
          Expanded(
            child: Container(
              color: backGroundColor,
              child: Text(
                title,
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 18, color: titleColor),
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
              ),
              // flex: 5,
            ),
            flex: 3,
          ),
          // const Spacer(),
          rightTitle == ''
              ? Expanded(
                  flex: 1,
                  child: rightFinishBtn == false
                      ? Offstage(
                          offstage: rightIcon == '',
                          child: rightIcon == ''
                              ? null
                              : GestureDetector(
                                  child: Image.asset(
                                    rightIcon,
                                    width: 28.w,
                                    height: 28.w,
                                  ),
                                  onTap: () {
                                    rightBtnCallBack();
                                  }))
                      : GestureDetector(
                          child: Container(
                            padding: const EdgeInsets.fromLTRB(19, 6, 19, 6),
                            width: 62.w,
                            height: 30.h,
                            decoration: BoxDecoration(
                                borderRadius: RadiusStyle.radiusAll(15),
                                gradient: ColorStyle.linearForLoginBtnColor),
                            child: Center(
                              child: Text(
                                '完成',
                                style: Styles.whiteText_12,
                              ),
                            ),
                          ),
                          onTap: () {
                            debugPrint('完成');
                          },
                        ),
                  // flex:1,
                )
              : Expanded(
                  child: GestureDetector(
                  child: Text(rightTitle,
                      style: TextStyle(fontSize: 18, color: rightTitleColor)),
                  onTap: () {
                    rightBtnCallBack();
                  },
                ))
        ],
      ),
    );
  }
}
